using MailKit.Net.Smtp;
using Microsoft.Extensions.Configuration;
using MimeKit;
using MimeKit.Text;

var configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .AddUserSecrets<Program>()
    .Build();

var email = new MimeMessage();
email.From.Add(MailboxAddress.Parse(configuration.GetSection("Email:From").Value));
email.To.Add(MailboxAddress.Parse(configuration.GetSection("Email:To").Value));
email.Subject = "Email Test Demo(Mailkit)";
email.Body = new TextPart(TextFormat.Plain) { Text = "Example Plain Text Message Body" };

using var smtpClient = new SmtpClient();
smtpClient.Connect("smtpdm.aliyun.com", 25, MailKit.Security.SecureSocketOptions.StartTls);
smtpClient.Authenticate(configuration.GetSection("Email:UserName").Value, configuration.GetSection("Email:Password").Value);
smtpClient.Send(email);
smtpClient.Disconnect(true);